<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./test01.js"></script>
</head>
<body>
    <input type="text" name="" id="name">
    <input type="text" name="" id="age">
    <button type="button" id="btn1">提交</button>
    <button type="button" id="btn2">查询</button>
    <div class="text"></div>
    <script>
        var username = document.getElementById('name')
        var age = document.getElementById('age')
        var btn1 = document.getElementById('btn1')
        var btn2 = document.getElementById('btn2')
        var text = document.querySelector(".text")
        btn1.onclick = function(){
            console.log(11);
            var str = 'userName='+username.value+'&userAge='+age.value;
            ajax({
                url:`http://localhost:10000/add?${str}`,
                // data:{
                //     name:'11',
                //     age:'10'
                // },
                callback(res) {
                    console.log(res);
                }
            })
        }
        btn2.onclick = function(){
            console.log(11);
            var str = 'userName='+username.value+'&userAge='+age.value;
            ajax({
                url:`http://localhost:10000/select`,
                // data:{
                //     name:'11',
                //     age:'10'
                // },
                callback(res) {
                    text.innerHTML = res
                    console.log(res);
                }
            })
        }
    </script>
</body>
</html>